package aftersale

import (
	"context"
	// "fmt"

	"mall/common/utils/pointy"
	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"
	"mall/service/backend/common/i18n"

	// "github.com/sirupsen/logrus"
	"github.com/zeromicro/go-zero/core/logx"
)

type GetPredefinedListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetPredefinedListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPredefinedListLogic {
	return &GetPredefinedListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetPredefinedListLogic) GetPredefinedList() (*types.OrderPredefinedListResp, error) {
	statusList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("success"),
			Name:  pointy.GetPointer("售后完成"),
			Slug:  pointy.GetPointer("success"),
			Value: pointy.GetPointer("1"),
		},
		{
			Key:   pointy.GetPointer("pending"),
			Name:  pointy.GetPointer("待审核"),
			Slug:  pointy.GetPointer("pending"),
			Value: pointy.GetPointer("2"),
		},
		{
			Key:   pointy.GetPointer("awaitReturn"),
			Name:  pointy.GetPointer("等待用户退货"),
			Slug:  pointy.GetPointer("awaitReturn"),
			Value: pointy.GetPointer("3"),
		},
		{
			Key:   pointy.GetPointer("awaitConfirm"),
			Name:  pointy.GetPointer("用户已发退货"),
			Slug:  pointy.GetPointer("awaitConfirm"),
			Value: pointy.GetPointer("4"),
		},
		{
			Key:   pointy.GetPointer("awaitRefund"),
			Name:  pointy.GetPointer("等待退款"),
			Slug:  pointy.GetPointer("awaitRefund"),
			Value: pointy.GetPointer("5"),
		},
		{
			Key:   pointy.GetPointer("awaitBarter"),
			Name:  pointy.GetPointer("等待仓库发换货"),
			Slug:  pointy.GetPointer("awaitBarter"),
			Value: pointy.GetPointer("6"),
		},
		{
			Key:   pointy.GetPointer("shipped"),
			Name:  pointy.GetPointer("已经发货，仓库已发换货"),
			Slug:  pointy.GetPointer("shipped"),
			Value: pointy.GetPointer("7"),
		},
		{
			Key:   pointy.GetPointer("closed"),
			Name:  pointy.GetPointer("售后关闭，用户取消申请"),
			Slug:  pointy.GetPointer("closed"),
			Value: pointy.GetPointer("8"),
		},
		{
			Key:   pointy.GetPointer("timeout"),
			Name:  pointy.GetPointer("售后超时，用户未退货"),
			Slug:  pointy.GetPointer("timeout"),
			Value: pointy.GetPointer("9"),
		},
		{
			Key:   pointy.GetPointer("rejected"),
			Name:  pointy.GetPointer("已驳回"),
			Slug:  pointy.GetPointer("rejected"),
			Value: pointy.GetPointer("10"),
		},
	}

	formDefault := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("approved"),
			Name:  pointy.GetPointer("同意"),
			Value: pointy.GetPointer("1"),
		},
		{
			Key:   pointy.GetPointer("rejected"),
			Name:  pointy.GetPointer("驳回"),
			Value: pointy.GetPointer("2"),
		},
		{
			Key:   pointy.GetPointer("returned"),
			Name:  pointy.GetPointer("已退回"),
			Value: pointy.GetPointer("3"),
		},
		{
			Key:   pointy.GetPointer("confirmed"),
			Name:  pointy.GetPointer("仓库已接收退货"),
			Value: pointy.GetPointer("4"),
		},
		{
			Key:   pointy.GetPointer("refunded"),
			Name:  pointy.GetPointer("已退款"),
			Value: pointy.GetPointer("5"),
		},
		{
			Key:   pointy.GetPointer("shipped"),
			Name:  pointy.GetPointer("仓库已发换货"),
			Value: pointy.GetPointer("6"),
		},
		{
			Key:   pointy.GetPointer("bartered"),
			Name:  pointy.GetPointer("用户已签收换货"),
			Value: pointy.GetPointer("7"),
		},
		{
			Key:   pointy.GetPointer("canceled"),
			Name:  pointy.GetPointer("用户已取消申请"),
			Value: pointy.GetPointer("8"),
		},
		{
			Key:   pointy.GetPointer("timeouted"),
			Name:  pointy.GetPointer("售后超时"),
			Value: pointy.GetPointer("9"),
		},
	}

	orderTypeList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("refund"),
			Name:  pointy.GetPointer("仅退款"),
			Slug:  pointy.GetPointer("refund"),
			Value: pointy.GetPointer("1"),
		},
		{
			Key:   pointy.GetPointer("return"),
			Name:  pointy.GetPointer("退货退款"),
			Slug:  pointy.GetPointer("return"),
			Value: pointy.GetPointer("2"),
		},
		{
			Key:   pointy.GetPointer("barter"),
			Name:  pointy.GetPointer("换货"),
			Slug:  pointy.GetPointer("barter"),
			Value: pointy.GetPointer("3"),
		},
	}

	metaKeyList := []*types.MetaInfo{
		{
			Key:  pointy.GetPointer("title"),
			Name: pointy.GetPointer("标题"),
			Slug: pointy.GetPointer("title"),
		},
		{
			Key:  pointy.GetPointer("keywords"),
			Name: pointy.GetPointer("关键词"),
			Slug: pointy.GetPointer("keywords"),
		},
		{
			Key:  pointy.GetPointer("description"),
			Name: pointy.GetPointer("描述"),
			Slug: pointy.GetPointer("description"),
		},
	}

	return &types.OrderPredefinedListResp{
		BaseDataInfo: types.BaseDataInfo{
			Success: true,
			Msg:     l.svcCtx.Trans.Trans(l.ctx, i18n.Success),
		},
		Data: types.OrderPredefinedListInfo{
			StatusList:    statusList,
			MetaKeyList:   metaKeyList,
			OrderTypeList: orderTypeList,
			FormDefault:   formDefault,
		},
	}, nil
}
